<?
include('../db/koneksi.php');
$nm_tbl=$_POST['nm_tbl'];
$result = mysql_query("SHOW COLUMNS FROM $nm_tbl");
$judul_atas=split('_',strtolower($nm_tbl));
$jum_atas=count($judul_atas);
$title='Form Input';
for($a=0;$a<$jum_atas;$a++){
$title=$title.' '.ucwords($judul_atas[$a]);
}

?>
<hr>

<code>

&lt;?<br>
include('../json/header_table.php');<br>
?&gt;
$("#flex1").flexigrid({<br>
	url: '<?=$nm_tbl?>_json.php',<br>
	dataType: 'json',<br>
	colModel : [<br>
	{display: ' Edit', name : 'edit', width : 100, sortable : false, align: 'center'},<br>
	{display: ' Delete', name : 'delete', width : 100, sortable : false, align: 'center'},<br>
<?
//$arrNama=split(",",$nama);
//$arrLabel=split(",",$label);
//$jumlah_kolom = count($arrNama);
$j=1;
if (mysql_num_rows($result) > 0) {

    while ($row = mysql_fetch_assoc($result)) {
	
	$yap=split('_',strtolower($row['Field']));
	$index[$j]=strtolower($row['Field']);
	$jenis=$row['Type'];
	$jum=count($yap);
	$judul=null;
	for($i=0;$i<$jum;$i++){
	$judul=$judul.' '.ucwords($yap[$i]);
	}
	
	?>
	{display: '<?=$judul?>', name : '<?=strtolower($row['Field']);?>', width : 100, sortable : true, align: 'center'},<br>
	<? 
	?>
	
  <? 
 $j++;
 }

}
//echo '&lt;/tr&gt;<br>';



?>
	],<br>
	buttons : [<br>
		{name: 'Add', bclass: 'add', onpress : Add},<br>		
		{separator: true}<br>
		],<br>
	searchitems : [<br>
		{display: 'ISO', name : 'iso'},<br>
		{display: 'Name', name : 'name', isdefault: true}<br>
		],<br>
	sortname: "<?=$index[1]?>",<br>
	sortorder: "asc",<br>
	usepager: true,<br>
	title: '<?=$nm_tbl?>',<br>
	useRp: true,<br>
	rp: 15,<br>
	showTableToggleBtn: true,<br>
	width: 890,<br>
	onSubmit: addFormData,<br>
	height: 200<br>
});

//This function adds paramaters to the post of flexigrid. You can add a verification as well by return to false if you don't want flexigrid to submit			<br>
function addFormData(){<br>
	//passing a form object to serializeArray will get the valid data from all the objects, but, if the you pass a non-form object, you have to specify the input elements that the data will come from<br>
	var dt = $('#sform').serializeArray();<br>
	$("#flex1").flexOptions({params: dt});<br>
	return true;<br>
}<br>
	
$('#sform').submit(function (){<br>
	$('#flex1').flexOptions({newp: 1}).flexReload();<br>
	return false;<br>
});<br>
function Add()<br>
{<br>
popUp('add_<?=$nm_tbl?>.php');<br>
}<br>
function openPop(a,kode)<br>
{<br>
popUp(a+"?kode="+kode);<br>
}<br>
function hapus_data(kode)<br>
{<br>
var konfirmasi;<br>
konfirmasi=confirm('Anda ingin menghapus data ini');<br>
var url='hapus_data_<?=$nm_tbl?>.php';<br>
	if(konfirmasi){<br>
	$.ajax({	<br>
	type: "POST",<br>
	url: url,<br>
	data: {kode:kode},<br>
	success: function (data)<br>
	{<br>
	if(data==1)<br>
	{<br>
		alert('sukses hapus');<br>
		location.reload();<br>
	}<br>
	}<br>
	//dataType: dataType<br>
	});<br>
	}<br>
}<br>
function Delete()<br>
{<br>
	alert('Delete');<br>
}<br>
&lt;?
//============================= Button ============================<br>


include('../json/footer_table.php');<br>
?&gt;


</code>